package collection.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;

public class StreamApiDemo2 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Random random = new Random();
        for(int i = 0; i < 10; i++) {
            list.add(random.nextInt(10));
        }

        System.out.println(list);

        Optional<Integer> value = list.stream().min((a,b)->a-b);
        System.out.println(value.get());

        value = list.stream().max((a,b)->a-b);
        System.out.println(value.get());

        value = list.stream().reduce((a,b)->a+b);
        System.out.println(value.get());

        Boolean anyMatch = list.stream().anyMatch(e -> e%2==0);
        System.out.println(anyMatch);
    }
}
